package com.gzk.oeno.ihm.tables.model;

import java.util.Collection;

import com.gzk.oeno.business.appellation.Appellation;
import com.gzk.oeno.business.pays.Pays;
import com.gzk.oeno.business.terroir.Terroir;
import com.gzk.oeno.business.typevin.TypeVin;
import com.gzk.oeno.business.vin.Vin;
import com.gzk.oeno.ihm.tables.renderer.CenteredCellRenderer;
import com.gzk.oeno.ihm.tables.renderer.CollectionCellRenderer;
import com.gzk.oeno.ihm.tables.renderer.NameCellRenderer;
import com.gzk.oeno.ihm.tables.renderer.TypeVinCellRenderer;
import com.gzk.utils.ihm.UIUtils;
import com.gzk.utils.ihm.table.SmartField;
import com.gzk.utils.ihm.table.SmartTableModel;

public class VinModel extends SmartTableModel<Vin> {

	public static final int TYPE 		= 0;
	public static final int PAYS 		= TYPE + 1;
	public static final int TERROIR 	= PAYS + 1;
	public static final int NOM 		= TERROIR + 1;
	public static final int MILLESIME 	= NOM + 1;
	public static final int APPELLATION = MILLESIME + 1;
	public static final int PRODUCTEUR 	= APPELLATION + 1;
	public static final int COMPO 		= PRODUCTEUR + 1;
	public static final int RECOMPENSE 	= COMPO + 1;
	public static final int CODES 		= RECOMPENSE + 1;
	public static final int LIENS 		= CODES + 1;
	public static final int PRIX 		= LIENS + 1;
	
	
	private static final SmartField[] FIELDS = new SmartField[]{
		new SmartField(TYPE, "Type", TypeVin.class, 5, new TypeVinCellRenderer()),
		new SmartField(PAYS, "Pays", Pays.class, 20, new NameCellRenderer()),
		new SmartField(TERROIR, "Terroir", Terroir.class, 25, new NameCellRenderer()),
		new SmartField(NOM, "Nom", String.class, 25),
		new SmartField(MILLESIME, "Millesime", Integer.class, 8, new CenteredCellRenderer()),
		new SmartField(APPELLATION, "Appellation", Appellation.class, 20, new NameCellRenderer()),
		new SmartField(PRODUCTEUR, "Producteur", String.class, 20),
		new SmartField(COMPO, "", Collection.class, 5, new CollectionCellRenderer(UIUtils.loadSilentIcon("icons/grapes_16.png"), null)),
		new SmartField(RECOMPENSE, "", Collection.class, 5, new CollectionCellRenderer(UIUtils.loadSilentIcon("icons/medal_16.png"), null)),
		new SmartField(CODES, "", Collection.class, 5, new CollectionCellRenderer(UIUtils.loadSilentIcon("icons/tags_16.png"), null)),
		new SmartField(LIENS, "", Collection.class, 5, new CollectionCellRenderer(UIUtils.loadSilentIcon("icons/web_16.png"), null)),
		new SmartField(PRIX, "", Collection.class, 5, new CollectionCellRenderer(UIUtils.loadSilentIcon("icons/cart_16.png"), null))
	};

	
	public VinModel() {
		super(FIELDS);
	}

	@Override
	protected Object getObjectMapping(Vin mappable, int col) {
		switch (col){
		case TYPE:
			return mappable.getType();
		case PAYS:
			return mappable.getPays();
		case TERROIR:
			return mappable.getTerroir();
		case NOM:
			return mappable.getName();
		case MILLESIME:
			return mappable.getMillesime();
		case APPELLATION:
			return mappable.getAppellation();
		case PRODUCTEUR:
			return mappable.getProducteur();
		case COMPO:
			if (mappable.getComposition() != null)
				return mappable.getComposition().entrySet();
		case RECOMPENSE:
			if (mappable.getRecompenses() != null)
				return mappable.getRecompenses().entrySet();
		case CODES:
			if (mappable.getCodes() != null)
				return mappable.getCodes().entrySet();
		case LIENS:
			return mappable.getLiens();
		case PRIX:
			return mappable.getPrix();
		}
		return null;
	}

}
